package com.ljyhhh.SmartCity.utils

import android.content.Context
import android.content.SharedPreferences
import com.ljyhhh.SmartCity.base.user.User

class DateSharedPreferences(context: Context) {
    val sharedPref :SharedPreferences
    init {
        sharedPref= context.getSharedPreferences("config",Context.MODE_PRIVATE)
    }
    fun checkAutoLogin() = sharedPref.getBoolean("auto_login",false)
    fun getUserinfo(): User? {
        val uname=sharedPref.getString("username","")
        val pwd=sharedPref.getString("password","")
        return uname?.let {
            pwd?.let {
                    it1 -> User(username = it, password = it1) }
        }
    }

    fun setUserInfo(user:User){
        with(sharedPref.edit()){
            putBoolean("auto_login",true)
            putString("username",user.username)
            putString("password",user.password)
            apply()
        }
    }
}